package com.my.web;

import com.my.annotation.OperationLogAnnotation;
import com.my.bean.User;
import com.my.common.result.R;
import com.my.constant.OperationType;
import com.my.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author marshal
 * @date 2021-06-08
 */
@RestController
@Tag(name = "用户管理接口")
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/save")
    @Operation(summary = "新增")
    @OperationLogAnnotation(module = "用户模块", type = OperationType.ADD, description = "新增")
    public R save(@RequestBody User user) {
        return R.success(this.userService.addUser(user));
    }

    @PutMapping("/update")
    @Operation(summary = "更新")
    @OperationLogAnnotation(module = "用户模块", type = OperationType.UPDATE, description = "保存")
    public R update(@RequestBody User user) {
        return R.success(this.userService.updateById(user));
    }

    @GetMapping("/getById/{id}")
    @Operation(summary = "根据ID查询")
    @OperationLogAnnotation(module = "用户模块", type = OperationType.QUERY, description = "根据ID查询")
    public R query(@PathVariable Long id) {
        return R.success(this.userService.getById(id));
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "根据ID删除")
    @OperationLogAnnotation(module = "用户模块", type = OperationType.DELETE, description = "根据ID删除")
    public R delete(@PathVariable Long id) {
        return R.success(this.userService.getById(id));
    }
}
